'use strict';
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const a = require('../../nodes/identity.cjs'),
  f = require('../../nodes/Pair.cjs'),
  p = require('../../nodes/Scalar.cjs'),
  g = require('../../nodes/YAMLSeq.cjs');
function u(i, n) {
  if (a.isSeq(i))
    for (let o = 0; o < i.items.length; ++o) {
      let e = i.items[o];
      if (!a.isPair(e)) {
        if (a.isMap(e)) {
          e.items.length > 1 &&
            n('Each pair must have its own sequence indicator');
          const r = e.items[0] || new f.Pair(new p.Scalar(null));
          if (
            (e.commentBefore &&
              (r.key.commentBefore = r.key.commentBefore
                ? `${e.commentBefore}
${r.key.commentBefore}`
                : e.commentBefore),
            e.comment)
          ) {
            const c = r.value ?? r.key;
            c.comment = c.comment
              ? `${e.comment}
${c.comment}`
              : e.comment;
          }
          e = r;
        }
        i.items[o] = a.isPair(e) ? e : new f.Pair(e);
      }
    }
  else n('Expected a sequence for this tag');
  return i;
}
function y(i, n, o) {
  const { replacer: e } = o,
    r = new g.YAMLSeq(i);
  r.tag = 'tag:yaml.org,2002:pairs';
  let c = 0;
  if (n && Symbol.iterator in Object(n))
    for (let t of n) {
      typeof e == 'function' && (t = e.call(n, String(c++), t));
      let s, l;
      if (Array.isArray(t))
        if (t.length === 2) (s = t[0]), (l = t[1]);
        else throw new TypeError(`Expected [key, value] tuple: ${t}`);
      else if (t && t instanceof Object) {
        const m = Object.keys(t);
        if (m.length === 1) (s = m[0]), (l = t[s]);
        else
          throw new TypeError(
            `Expected tuple with one key, not ${m.length} keys`,
          );
      } else s = t;
      r.items.push(f.createPair(s, l, o));
    }
  return r;
}
const h = {
  collection: 'seq',
  default: !1,
  tag: 'tag:yaml.org,2002:pairs',
  resolve: u,
  createNode: y,
};
exports.createPairs = y;
exports.pairs = h;
exports.resolvePairs = u;
